package com.tsmti.webservice.entity;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

import java.io.Serializable;

/**
 * @Package：com.tsmti.core.common.entity
 * @Class：AbstractEntity
 * @Description： TODO
 * @Author：zcw
 * @Date：Created in 2018/5/16 18:57
 * @Company:
 * @Version：
 * @Modified By:
 */
public abstract class AbstractEntity<ID> implements Serializable {
    /**
     * getId
     * @return
     */
    public abstract ID getId();

    /**
     *setId
     * @param id
     */
    public abstract void setId(ID id);

    /**
     * isNew
     * @return
     */
    public boolean isNew() {

        return null == getId();
    }

    /**
     * equals
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {

        if (null == obj) {
            return false;
        }

        if (this == obj) {
            return true;
        }

        if (!getClass().equals(obj.getClass())) {
            return false;
        }

        @SuppressWarnings("unchecked")
        AbstractEntity<ID> that = (AbstractEntity<ID>) obj;

        return null == this.getId() ? false : this.getId().equals(that.getId());
    }

    /**
     * hashCode
     * @return
     */
    @Override
    public int hashCode() {

        int hashCode = 17;

        hashCode += null == getId() ? 0 : getId().hashCode() * 31;

        return hashCode;
    }

    /**
     * toString
     * @return
     */
    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this);
    }
}
